package com.situ.hello;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class WidgetActivity extends Activity {
    private static final String TAG = "WidgetActivity";
    private Button button;
    private EditText editText;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 绑定布局
        setContentView(R.layout.activity_widget);

        Log.d(TAG, "onCreate: ");

        button = findViewById(R.id.btn);
        editText = findViewById(R.id.editText);

        // 1、监听Button的点事事件（匿名内部类）
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // syso
                // sout
                // System.out.println();
                System.out.println("Button被点击");
                // 拿到EditText里面的内容
                String data = editText.getText().toString();
                Toast.makeText(WidgetActivity.this, data, Toast.LENGTH_LONG).show();

                AlertDialog alertDialog = new AlertDialog.Builder(WidgetActivity.this)
                        .setTitle("Dialog对话框")
                        .setIcon(R.mipmap.ic_launcher)
                        .setMessage("您确认要删除么?")
                        .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Toast.makeText(WidgetActivity.this, "您点击了确定", Toast.LENGTH_LONG).show();
                            }
                        })
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Toast.makeText(WidgetActivity.this, "您点击了取消", Toast.LENGTH_LONG).show();
                            }
                        }).create();
                alertDialog.show();

            }
        });
    }
}
